<template>
  <div class="rights">
    <el-card class="avue_height">
      <el-button type="primary" @click="addLevel" style="margin-bottom:20px">新增权益</el-button>
      <avue-crud
        ref="crud"
        style="width:100%"
        :data="loadData"
        :option="tableOption"
        :table-loading="loading"
      >
      <template slot-scope="scope" slot="indexLabel">
        <span>{{scope.row.$index+(page.current - 1) * page.size + 1}}</span>
      </template>
        <template slot="menu" slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.row)">编辑</el-button>
          <el-button
            type="text"
            @click="switchs(scope.row)"
            :icon="scope.row.isenabled == '01'?'el-icon-circle-close':'el-icon-circle-check'"
          >{{scope.row.isenabled == '01'?'停用':'启用'}}</el-button>
          <el-button type="text" icon="el-icon-delete" @click="del(scope.row)">删除</el-button>
        </template>
      </avue-crud>
      <template>
        <div style="width:100%;position:relative;height:50px">
          <el-pagination
            :page-sizes="[10, 20,30,40, 50, 100]"
            :pager-count="7"
            :current-page="page.current"
            :page-size="page.size"
            :total="page.total"
            layout="total, sizes, prev, pager, next, jumper"
            style="margin:2% 0;position:absolute;right:1%"
            background
            @size-change="sizeChange"
            @current-change="currentChange"
          ></el-pagination>
        </div>
      </template>
    </el-card>

    <el-dialog :title="dialogTitle==1?'新增权益':'编辑权益'" :visible.sync="dialogVisible" width="30%">
      <!-- ref当前标签，relForm表单 -->
      <!-- <formNode
        :formNodeList="formNodeList"
        :form="form"
        ref="form"
        :relForm="'form'"
        :rules="rules"
        :labelWidth="'120px'"
      />-->
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="权益名称：" prop="equityRuleName">
          <el-input
            v-model="ruleForm.equityRuleName"
            placeholder="请输入权益名称，不超过30个字"
            :disabled="typeof(ruleForm.id)==='number'"
            :maxlength="30"
            style="width:100%"
          ></el-input>
        </el-form-item>
        <el-form-item label="权益类型：" prop="equityRuleType">
          <el-select
            v-model="ruleForm.equityRuleType"
            style="width:100%"
            @change="equityRuleTypeChange"
          >
            <el-option
              :label="i.label"
              :value="i.value"
              v-for="i in equityRuleTypeList"
              :key="i.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="权益说明：" prop="equityRuleExplain">
          <el-input v-model="ruleForm.equityRuleExplain" type="textarea" style="width:100%"></el-input>
        </el-form-item>

        <el-form-item label="积分规则：" prop="integralRuleId" v-if="ruleForm.equityRuleType == '00'">
          <el-select v-model="ruleForm.integralRuleId" style="width:100%">
            <el-option
              :label="i.label"
              :value="i.value"
              v-for="i in integralRuleTypeList"
              :key="i.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <div v-if="ruleForm.equityRuleType == '02'">
          <el-form-item label="会员等级：" prop="gradeId">
            <el-select v-model="ruleForm.gradeId" placeholder="请选择会员等级" style="width:100%">
              <el-option
                v-for="item in hydjList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="权益内容：" prop="equityRuleContent">
            <el-checkbox-group
              v-model="ruleForm.equityRuleContent"
              @change="equityRuleContentChange"
            >
              <el-checkbox label="00">积分</el-checkbox>
              <el-checkbox label="01">优惠券</el-checkbox>
            </el-checkbox-group>
            <!-- <el-radio-group    v-model="ruleForm.equityRuleContent"
              @change="equityRuleContentChange">
              <el-radio label="00">积分</el-radio>
              <el-radio label="01">优惠券</el-radio>
            </el-radio-group> -->
          </el-form-item>
          <el-form-item
            label="赠送积分："
            prop="giveIntegral"
            v-if="ruleForm.equityRuleContent.some((item, index) => {return item == '00'})"
          >
            <el-input-number
              v-model="ruleForm.giveIntegral"
              controls-position="right"
              placeholder="请输入赠送积分数量"
              style="width:100%"
              :min="1"
            ></el-input-number>
          </el-form-item>
          <el-form-item
            label="优惠券："
            prop="couponId"
            v-if="ruleForm.equityRuleContent.some((item, index) => {return item == '01'})"
          >
            <el-select v-model="ruleForm.couponId" placeholder="请选择优惠券" style="width:100%">
              <el-option
                v-for="item in youHuiList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>
        <el-form-item label="状态" prop="isenabled">
          <el-radio-group v-model="ruleForm.isenabled">
            <el-radio :label="i.value" v-for="i in isenabledList" :key="i.value">{{i.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handlClose">取 消</el-button>
        <el-button type="primary" @click="handlSure" :loading="loadingSure" v-if="dialogTitle">保 存</el-button>
        <el-button type="primary" @click="handlUpdate" :loading="loadingSure" v-else>修 改</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script src="./index.js"></script>
<style lang="scss" scoped>
</style>